/**
 * 1。Promise是一个类，在执行的时候需要传一个执行器进去，执行器立即调用
 * 2.Promise有三种状态  成功fulfilled  失败rejected 等待pending
 *     pending ==> fulfilled
 *     pending ==> reject 
 *     状态一旦确定就不可更改
 * 3.resolve和reject函数式用来更改状态的
 *     resolve: fulfilled
 *     reject: rejected
 */
const MyPromise = require("./MyPromise.js");
function p1(){
  return new MyPromise((resolve,rejct)=>{
    setTimeout(() => {
      resolve("p1")
    }, 2000);
  })
}

function p2(){
  return new MyPromise((resolve,rejct)=>{
      resolve("p2")
  })
}

p2().finally(()=>{
  console.log("finally")
  return p1();
}).then(value=>{
  console.log(value)
},reason=>{
  console.log(reason)
})